package ModelLayer;

import java.util.*;

public class SaleContainer{
    private ArrayList<Sale> saleContainer;
    private static SaleContainer instance;
//     private  Sale sale ;
    private SaleContainer(){
        saleContainer = new ArrayList<Sale>();
//         sale = new Sale(0,1,1);
//         addSale(sale);
//         sale = new Sale(1,1,1);
//         addSale(sale);
    }

    public static SaleContainer getInstance(){
        if(instance == null){
            instance = new SaleContainer();

        }
        return instance;
    }

    public void addSale(Sale sale){
        saleContainer.add(sale);
    }

    public Sale findSaleById(int id){
        Sale sObject = null;
        int index = 0;
        boolean found = false;
        while(index < saleContainer.size() && !found)
        {
            sObject = saleContainer.get(index); 
            if(sObject.getId()== id)
            {
                found = true;
            }
            else{
                index++;
            }
        }
        if(found){
            return saleContainer.get(index) ;
        }else{
            return  null;
        }
    }

    public ArrayList<Sale> getSaleList()
    {
        return saleContainer;
    }

    public void deleteSale(Sale p){
        if(saleContainer.contains(p))
            saleContainer.remove(p);
    }
}